const userModel=require('../model/user');
// const path = require('path');
module.exports={
     getLoginPage(req, res){
         res.render('admin/login');
        //  res.render(path.join(__dirname, '../views/admin/login.ejs'));
     },
     userLogin(req,res){
         let {email,password}=req.body;
         userModel.userLogin(email,r=>{
             if(r){
                if(r.password==password){
                    req.session.isLogin=true;
                    req.session.userInfo=r;
                    res.send({
                        code:200,
                        msg:'ok',
                        data:{
                            avatar:r.avatar,
                            nickname: r.nickname
                        }
                    });
                }else{
                    res.send({
                        code:400,
                        msg:'密码有误'
                    })
                }
             }else{
                res.send({
                    code: 400,
                    msg: '邮箱不正确'
                })
             }
         })
     },
     logout(req,res){
         req.session.destroy();
         res.send({code:200,msg:'ok'})
     }
}